package com.hcinfos.gsoo.adapter;

import com.hcinfos.gsoo.R;

import android.content.Context;
import android.database.Cursor;
import android.support.v4.widget.CursorAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class SearchCityAdapter extends CursorAdapter {

	private LayoutInflater layoutInflater;
	private Context mContext;

	public SearchCityAdapter(Context context, Cursor c, boolean autoRequery) {
		super(context, c, autoRequery);
		this.mContext = context;
		layoutInflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public CharSequence convertToString(Cursor cursor) {
		return cursor == null ? "" : cursor.getString(cursor
				.getColumnIndex("cityName"));
	}

	@Override
	public void bindView(View view, Context arg1, Cursor curosr) {

		setView(view, curosr);
	}

	private void setView(View view, Cursor cursor) {
		TextView tvWordItem = (TextView) view.findViewById(R.id.statio_tv);
		tvWordItem.setText(cursor.getString(cursor.getColumnIndex("cityName")));
	}

	@Override
	public View newView(Context arg0, Cursor cursor, ViewGroup arg2) {
		View view = layoutInflater.inflate(R.layout.search_info_item, null);
		setView(view, cursor);
		return view;
	}
}
